<extend name="Index/index"/>
<block name="content">
    <!--<div class="view-product" style="margin-top: 50px">-->
    <div class="info-center">
        <div class="manage-head">
            <h6 class="padding-left manage-head-con">{{$title}}</h6>
        </div>
        <div class="offcial-table input-table table-margin clearfix">
            <div class="demoTable">
                <span onclick="addSort()" class="layui-btn layui-btn-normal">添加分类</span>
            </div>
            <if condition="$sortList eq null">
                <div class="tr non-info show border-bottom-none">
                    <span>没查询到符合条件的记录</span>
                </div>
                <else />
                <table class="layui-table text-center">
                    <tr>
                        <th class="text-center">ID</th>
                        <th class="text-center">分类名</th>
                        <th class="text-center">是否使用</th>
                        <th class="text-center">创建时间</th>
                        <th class="text-center">操作</th>
                    </tr>
                    <foreach  name="sortList" item="vo" key="k">
                        <tr>
                            <td>{{$vo.id}}</td>
                            <td>{{$vo.name}}</td>
                            <td onclick="changeUse(this)">
                                <eq name="vo.is_use" value="1">
                                    <a href="{{:U('Communicate/isUse',array('id'=>$vo['id'],'use'=>$vo['is_use']))}}"><i class="layui-icon" style="color: #1E9FFF;">&#xe618;</i></a>
                                    <else/>
                                    <a href="{{:U('Communicate/isUse',array('id'=>$vo['id'],'use'=>$vo['is_use']))}}"><i class="layui-icon" style="color: #1E9FFF;">&#x1006;</i></a>
                                </eq>
                            </td>
                            <td>{{$vo.create_time}}</td>
                            <td><span class="layui-btn layui-btn-normal" onclick="changeName(this)">编辑分类名</span></td>
                        </tr>
                    </foreach>
                </table>

            </if>

        </div>
    </div>
    <div class="show-page padding-big-right hidden">
        <div class="page">
        </div>
    </div>
    <!--</div>-->

    <script charset="utf-8">
        function changeName (obj){
            var id = $(obj).parent().parent().find("td").eq(0).text();
            var name = $(obj).parent().parent().find("td").eq(1).text();
            layui.use('layer', function(){
                var layer = layui.layer;
                layer.prompt({
                    formType: 2,
                    value: name,
                    title: '分类名',
                    shade:0,
                    area: ['200px', '40px'] //自定义文本域宽高
                }, function(value, index, elem){
                    // console.log(value)
                    $.ajax({
                        url : '{{:U("Communicate/editSort")}}',
                        type : "get",
                        data : {id:id,name:value},
                        // data : "id="+id+"&name="+value,
                        success : function(msg){
                            // if(msg === 1){
                            window.location.href = '{{:U("Communicate/cateList")}}';
                            // }
                            // layer.close(index);
                        }
                    });

                });
            });
        }

        function addSort (){
            layui.use('layer', function(){
                var layer = layui.layer;
                layer.prompt({
                    formType: 2,
                    value: "",
                    title: '分类名',
                    shade:0,
                    area: ['200px', '40px'] //自定义文本域宽高
                }, function(value, index, elem){
                    // console.log(value)
                    $.ajax({
                        url : '{{:U("Communicate/addSort")}}',
                        type : "get",
                        data : {name:value},
                        data : {name:value},
                        // data : "id="+id+"&name="+value,
                        success : function(msg){
                            // if(msg === 1){
                            window.location.href = '{{:U("Communicate/cateList")}}';
                            // }
                            // layer.close(index);
                        }
                    });

                });
            });
        }
    </script>
</block>